#include <stdio.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <sys/types.h> 
#include <string.h>
#include <unistd.h>


int main(int argc, const char *argv[])
{
	int sockfd,acceptfd;
	struct sockaddr_in serveraddr;
	struct sockaddr_in clientaddr;
	socklen_t addrlen=sizeof(serveraddr);

	sockfd=socket(AF_INET,SOCK_STREAM,0);

	serveraddr.sin_family=AF_INET;
	serveraddr.sin_addr.s_addr=inet_addr(argv[1]);
	serveraddr.sin_port=htons(atoi(argv[2]));

	bind(sockfd,(struct sockaddr *)&serveraddr,addrlen);

	listen(sockfd,5);

	acceptfd=accept(sockfd,(struct sockaddr *)&clientaddr,&addrlen);

	char buf[128];
	while(1)
	{
//		recv(acceptfd,buf,128,0);
		int len=read(acceptfdfd,buf,128);
		if(len>0)
		{
			printf("%s\n",buf);
			memset(buf,0,128);
		}
	}
	return 0;
}
